<?php
defined('DEEPR_PATH') or define('DEEPR_PATH',dirname(__FILE__));
class DeeprBase
{
	public static $path=DEEPR_PATH;
	
	private static $_coreClasses=array(
		'CMap' => '/collections/CMap.php',
		'CException' => '/core/CException.php',
		'CHttpException' => '/core/CHttpException.php',
		'CWebApplication' => '/core/CWebApplication.php',
		'CHttpRequest' => '/core/CHttpRequest.php',
		'CHttpSession' => '/core/CHttpSession.php',
		'CWebUser' => '/core/CWebUser.php',
		'CHttpCookie' => '/core/CHttpCookie.php',
		'CRequestHandler' => '/core/CRequestHandler.php',
		'CRouteMapper' => '/core/CRouteMapper.php',
		'CController' => '/core/CController.php',
		'CBaseController' => '/core/CBaseController.php',
		'CTemplator' => '/core/CTemplator.php',
		'CBaseURLHandler' => '/core/CBaseURLHandler.php',
		'CPager' => '/core/CPager.php',
		'R' => '/orm/rb.php',
		'SmartyBC' => '/tpl/smarty/libs/SmartyBC.class.php',
		'FormValidator' => '/validators/formvalidator.php'
	);
	
	private static $_include_paths=array();
	
	public static function autoload($className)
	{
				if(isset(self::$_coreClasses[$className]))
				include(DEEPR_PATH.self::$_coreClasses[$className]);								
				else if (!empty(self::$_include_paths))
				{
					foreach(self::$_include_paths as $path)
					{
						if(file_exists($path.DIRECTORY_SEPARATOR.$className.'.php'))
						{
							require $path.DIRECTORY_SEPARATOR.$className.'.php';
						}
					}
				}
	}
	
	public static function autoloadByFullPath($path)
	{		
		if(is_file($path))
			include($path);	
	}
	
	public static function createInstance($class,$config=null)
	{
		return new $class($config);
	}
	
	public static function createWebApplication($config=null)
	{			
		return self::createInstance('CWebApplication',$config);
	}
		
	public static function defaultRequestHandler($class,$config=null)
	{
		return CRequestHandler::instance();
	}
	
	public static function addIncludePath($path)
	{
		array_push(self::$_include_paths, $path);
	}
	
	
	public static function t($category,$message,$params=array(),$source=null,$language=null)
	{
		echo $message;
	}

	public static function autoLoadCoreClasses()
	{		
		foreach (self::$_coreClasses as $key => $value) 
		{
			self::autoload($key);
		}
	}
	
}

spl_autoload_register(array('DeeprBase','autoload'));
